package com.wxx.generator;

import com.wxx.model.MainTemplateConfig;
import freemarker.template.TemplateException;

import java.io.File;
import java.io.IOException;

/**
 * 核心生成器(接收者)
 */
public class MainGenerator {
    public static void main(String[] args) throws TemplateException, IOException {
        //创建数据模型
        MainTemplateConfig mainTemplateConfig = new MainTemplateConfig();
        mainTemplateConfig.setAuthor("you");
        mainTemplateConfig.setOutputText("输出结果:");
        mainTemplateConfig.setLoop(true);
        doGenerate(mainTemplateConfig);

        /*String projectPath = System.getProperty("user.dir");//获取项目的根目录
        //输入路径
        String inputPath = projectPath + File.separator + "you-generator-demo-projects" + File.separator + "acm-template";
        //生成静态文件
        StaticGenerator.copyFilesByRecursive(inputPath, projectPath);

        //生成动态文件
        String dynamicInputPath = projectPath + File.separator + "you-generator-basic" + File.separator + "src/main/resources/templates/MainTemplate.java.ftl";
        String dynamicOutputPath = projectPath + File.separator + "acm-template/src/com/wxx/acm/MainTemplate.java";*/
    }

    /**
     * 生成(实际执行的功能)
     * @param model 数据模型
     */
    public static void doGenerate(Object model) throws IOException, TemplateException {

        String inputRootPath = "D:\\you-generator-code\\you-generator\\you-generator-demo-projects\\acm-template-pro";
        String outputRootPath = "D:\\you-generator-code\\you-generator";

        String inputPath;
        String outputPath;

        inputPath = new File(inputRootPath, "src/com/wxx/acm/MainTemplate.java.ftl").getAbsolutePath();
        outputPath = new File(outputRootPath, "src/com/wxx/acm/MainTemplate.java").getAbsolutePath();
        DynamicGenerator.doGenerate(inputPath, outputPath, model);


        inputPath = new File(inputRootPath, ".gitignore").getAbsolutePath();
        outputPath = new File(outputRootPath, ".gitignore").getAbsolutePath();
        StaticGenerator.copyFilesByRecursive(inputPath, outputPath);

        inputPath = new File(inputRootPath, "README.md").getAbsolutePath();
        outputPath = new File(outputRootPath, "README.md").getAbsolutePath();
        StaticGenerator.copyFilesByRecursive(inputPath, outputPath);

    }
}
